FROM python:3.11.8-slim-bullseye

# Python env
ENV PYTHONFAULTHANDLER=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONHASHSEED=random \
    PYTHONPATH=/python_modules \
# pip env
    PIP_NO_CACHE_DIR=off \
    PIP_DISABLE_PIP_VERSION_CHECK=on \
    PIP_DEFAULT_TIMEOUT=30 \
# DockerHOME
    DockerHOME=/docker_home \
# LlamaIndex
    LLAMA_INDEX_CACHE_DIR=/llama_cache \
# Database
    DB_PATH=/db/db.sqlite3

# VOLUME ["$DB_PATH", "$PYTHONPATH", "$LLAMA_INDEX_CACHE_DIR"]

WORKDIR $DockerHOME

RUN curl -fsSL https://ollama.com/install.sh | sh

COPY requirements.txt .
RUN pip install -r requirements.txt -i https://mirrors.cloud.tencent.com/pypi/simple -t $PYTHONPATH

COPY . $DockerHOME

RUN ls chatcollector/*db* | xargs rm -f
RUN sed -i 's/\r//' startup.sh

EXPOSE 8000

ENTRYPOINT bash startup.sh
